<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>商品列表</title>
  <style>
    body{
      margin: 0 auto;
      text-align: center;
      background-image: url("img/img.png");
      background-size: cover;
    }
    table{
      color: white;
    }
  </style>
</head>
<body>
<div>
  <h1 style="color: white">商品列表</h1>
  <table border="1" style="margin: 0 auto">
    <tr>
      <th>编号</th>
      <th>标题</th>
      <th>价格</th>
      <th>销量</th>
      <th>操作</th>
    </tr>
    <tr v-for="p in arr">
      <td>{{p.id}}</td>
      <td>{{p.title}}</td>
      <td>{{p.price}}</td>
      <td>{{p.saleCount}}</td>
      <td><a href="javascript: void(0)" @click="del(p.id)">删除</a>
        <a :href="'/updatePro.html?id='+p.id">修改</a>
      </td>
    </tr>
  </table>
</div>

<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>

<script>
  let v = new Vue({
    el:"table",
    data:{
      arr:[]
    },
    created: function (){
      axios.get("selectAll").then(function (response){
        v.arr = response.data;
      })
    },
    methods:{
      del(id){
        axios.get("/deleteById?id="+id).then(function (){
          alert("删除成功!");
          location.reload();
        })
      }
    }
  })
</script>
</body>
</html>